Allow to exclude certain target from nogo facts collection #4353
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Feature
What does this PR do? Why is it needed?
After #4268, nogo collects facts from all targets. So
go_register_nogo'sincludesandexcludesnow overlap with the JSON config'sonly_filesandexclude_files, which is to surppress nogo errors in certain files/targets. Meanwhile, collecting facts can be slow for very large Go packages for some analyzers, slower than compilation. To address the performance issue, this PR revertexcludesto its previous behavior: stop nogo from collecting facts from certain packages. To avoid collecting facts from IDL-generated code, users can do this:The
includesofgo_register_nogoa no-op with a warning message, so nogo collects facts from all packages unless excluded explicitly. Users have to use the JSON config to limit the scope of nogo validation.This PR also exclude all external targets from nogo validation by default, which is equivalent to
{ "_base": { "exclude_files": { "^external/": "external repositories" } } }Other notes for review
Alternatively, to be backward-compatible, we can add a flag or attribute like
exclude_collect_facts, but adding that on top ofexcludesandexclude_filesmakes hard to remember which is which.